package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xmy.cultivate.entity.TeacherPoint;
import com.xmy.cultivate.entity.TrainPromoteLookTeacher;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 资料查看教师 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2025-11-01
 */
public interface TrainPromoteLookTeacherMapper extends BaseMapper<TrainPromoteLookTeacher> {
    @Select({ "<script>",
            "SELECT * FROM (",
            "SELECT",
            " p_b_t.id as id," ,
            " GROUP_CONCAT( p_b_t.id ) AS id_str,",
            " p_b_t.teacher_id,",
            " GROUP_CONCAT( p_b_t.course_type_id ) AS course_type_id_str,",
            " p_b_t.year_part AS year_part,",
            " p_b_t.quarter_num AS quarter_num,",
            " p_b_t.lesson_type,",
            " CASE WHEN p_b_t.lesson_type = 1 THEN '精品课'",
            " WHEN p_b_t.lesson_type = 2 THEN '智能课'",
            " WHEN p_b_t.lesson_type = 3 THEN '刷题班'",
            " WHEN p_b_t.lesson_type = 4 THEN '教学艺术'",
            " END AS lesson_type_name,",
            " p_b_t.teacher_type,",
            " s.`name` AS teacher_name,",
            " p_b_t.year_class_id AS grade,",
            " GROUP_CONCAT( c_t.`name` ) AS course_type,",
            " s_j.NAME AS subject,",
            " '手动添加' AS entity_type, ",
            " p_b_t.type, ",
            "getDictName ( p_b_t.type, 45 ) AS type_str, ",
            "p_b_t.version_id, ",
            "e_v.name AS version_name ",
            " FROM",
            " train_promote_look_teacher p_b_t",
            " LEFT JOIN staff s ON p_b_t.teacher_id = s.id",
            " JOIN course_type c_t ON p_b_t.course_type_id = c_t.id",
            " JOIN subjects s_j ON s_j.id = p_b_t.subjects_id ",
            " LEFT JOIN edu_version e_v ON e_v.id = p_b_t.version_id ",
            " WHERE",
            " p_b_t.deleted = 0 ",
            " AND s.deleted = 0 ",
            " AND c_t.deleted = 0 ",
            " AND s_j.deleted = 0 ",
            "<if test ='subjectId != null and subjectId !=&apos;&apos;'>",
            "AND p_b_t.subjects_id = ${subjectId} ",
            "</if>",
            "<if test ='yearPart != null and yearPart !=&apos;&apos;'>",
            "AND p_b_t.year_part = ${yearPart} ",
            "</if>",
            "<if test ='quarterNum != null and quarterNum !=&apos;&apos;'>",
            "AND p_b_t.quarter_num = ${quarterNum} ",
            "</if>",
            "<if test ='lessonType != null and lessonType !=&apos;&apos;'>",
            "AND p_b_t.lesson_type = ${lessonType}",
            "</if>",
            "<if test ='teacherName != null and teacherName !=&apos;&apos;'>",
            "AND s.name LIKE '%${teacherName}%' ",
            "</if>",
            "<if test ='yearClassId != null and yearClassId !=&apos;&apos;'>",
            "AND p_b_t.year_class_id = ${yearClassId} ",
            "</if>",
            "<if test ='type != null and type !=&apos;&apos;'>",
            "AND p_b_t.type IN ( ${type})",
            "</if>",
            "<if test ='teacherType != null and teacherType !=&apos;&apos;'>",
            "AND p_b_t.teacher_type IN (${teacherType})",
            "</if>",
            "<if test ='versionId != null and versionId !=&apos;&apos;'>",
            "AND p_b_t.version_id IN (${versionId})",
            "</if>",
            "GROUP BY p_b_t.teacher_id,p_b_t.lesson_type,p_b_t.teacher_type,p_b_t.year_class_id,p_b_t.type,p_b_t.version_id",
            ") AS t",
            "WHERE 1=1",
            "<if test ='courseTypeId != null and courseTypeId !=&apos;&apos;'>",
            "AND ( find_in_set( ${courseTypeId}, course_type_id_str ))",
            "</if>",
            "</script>"})
    public IPage<TeacherPoint> findAllTeachingPoint(
            IPage<TeacherPoint> page,
            @Param("yearPart") String yearPart,
            @Param("quarterNum") String quarterNum,
            @Param("lessonType") String lessonType,
            @Param("teacherName") String teacherName,
            @Param("yearClassId") String yearClassId,
            @Param("courseTypeId") String courseTypeId,
            @Param("subjectId") String subjectId,
            @Param("type") String type,
            @Param("teacherType") String teacherType,
            @Param("versionId") String versionId
    );
}
